<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试</title>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
    let now = (new Date()).valueOf();
    let promiseList = [];
    const api='/api/index.php?'
    const userIds = [1,2,3,4,5,6,7,8,9,10];
    const userRetry = 10;
    const jqPromiseAjax = url => {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: url,
                type: 'get',
                dataType: 'json',
                success(res) {
                    resolve({'res':res,err:null,url:url})
                },
                error(err) {//吃掉这个错误,防止Promise.all 出现中断
                    resolve({'res':null,err:err,url:url})
                }
            })
        })
    }
    async function test(){
	    for(let i in userIds){
	        let userId = userIds[i];
	        for(let j=0;j<userRetry;j++){
	        	let url = api + 'user_id=' + userId;
	        	promiseList.push(jqPromiseAjax(url));
	        }
		}
		let results = await Promise.all(promiseList);

		$('body').append(`<p>全部完成,用时:${(new Date()).valueOf() - now}ms<p>`);
		for(let i in results){
			let res = results[i];
			if(res.res){
				$('body').append(`<p>${res.url}->访问成功,结果code:${res.res.status},msg:${res.res.msg}</p>`);
				if(res.res.data){
					$('body').append(`<p>具体奖品:${res.res.data.item}</p>`);
				}
			}else{
				$('body').append(`<p>${res.url}->访问失败,可能是网络问题</p>`);
			}

		}
	}
	test()
</script>
</head>
 
<body>

</body>
 
</html>